package com.btex.app.adapter;

import android.support.annotation.Nullable;
import android.widget.ProgressBar;

import com.btex.app.R;
import com.btex.app.entity.OrderBookInfo;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/5/16
 * @time 下午12:04
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class TradeDownAdapter extends BaseQuickAdapter<OrderBookInfo.DataBean.BuyBean, BaseViewHolder> {

    private String mMax;

    public TradeDownAdapter(@Nullable ArrayList<OrderBookInfo.DataBean.BuyBean> data, String max) {
        super(R.layout.activity_trede_down_item, data);
        mMax = max;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderBookInfo.DataBean.BuyBean item) {

        ProgressBar item_trade_progess = (ProgressBar) helper.getView(R.id.item_trade_progess);

        if (mMax.contains(".")) {
            String[] split1 = mMax.split("\\.");

            String max = split1[0];
            String max1 = split1[1];


            if (max.length() < 3) {

                String s = max + max1;
                item_trade_progess.setMax(Integer.parseInt(s));
                String amount = item.getAmount();
                String[] split2 = amount.split("\\.");
                String s0 = split2[0];
                String s1 = split2[1];
                String s2 = s0 + s1;
                if (s2.length() >= 9) {
                    String substring = s2.substring(0, 9);
                    item_trade_progess.setProgress(Integer.parseInt(substring));
                } else {
                    item_trade_progess.setProgress(Integer.parseInt(s2));
                }


            } else {

                boolean isOne = false;

                if (mMax.contains(".")) {
                    String[] split = mMax.split("\\.");

                    String max11 = split[0];
                    String max2 = split[1];

                    if (Integer.parseInt(max11) > 1) {
                        isOne = true;
                        item_trade_progess.setMax(Integer.valueOf(max11));
                    } else {
                        isOne = false;
                        item_trade_progess.setMax(Integer.valueOf(max2));
                    }

                }


                if (isOne) {
                    String amount = item.getAmount();
                    String[] split = amount.split("\\.");
                    String s = split[0];
                    item_trade_progess.setProgress(Integer.valueOf(s));


                } else {
                    String amount = item.getAmount();
                    String[] split = amount.split("\\.");
                    String s = split[1];
                    item_trade_progess.setProgress(Integer.valueOf(s));
                }

            }

        } else {
            String amount = item.getAmount();
            item_trade_progess.setMax(Integer.parseInt(mMax));
            item_trade_progess.setProgress(Integer.valueOf(amount));
        }


        helper.setText(R.id.activity_trede_tv_down_price, item.getPrice());
        helper.setText(R.id.activity_trede_tv_down_number, item.getAmount());

    }
}
